package unknow;

import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.ref.PhantomReference;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.SoftReference;
import java.lang.ref.WeakReference;
import java.math.BigDecimal;
import java.util.*;
import java.util.regex.Pattern;

/**
 * @author 李栋
 * @version 1.0.0
 * @className other.OtherTest.java
 * @createTime 2021年08月18日 21:36:00
 */
public class OtherTest {

    private static final Logger logger = LoggerFactory.getLogger(OtherTest.class);
    private static final Pattern COMPILE = Pattern.compile(" ");

    private Boolean flag;

    @Test
    public void test1() {
        // 左移
        int a = 2 << 3;
        logger.info(String.valueOf(a));
    }

    @Test
    public void test2() {
        // 左移
        char a = '张';
        logger.info(String.valueOf(a));
    }

    /**
     * java 四种引用
     */
    @Test
    public void test3() {
        // 强引用
        String str = "张三";
        // 软引用
        SoftReference<String> stringSoftReference = new SoftReference<>(str);
        // 弱引用
        WeakReference<String> weakReference = new WeakReference<>(str);

        // 虚引用
        ReferenceQueue<String> queue = new ReferenceQueue<>();
        PhantomReference<String> phantomReference = new PhantomReference<>(str, queue);


        logger.info(String.valueOf(stringSoftReference));
        logger.info(String.valueOf(weakReference));
        logger.info(String.valueOf(phantomReference));
    }


    @Test
    public void test4() {
        Boolean a;
        logger.info("test");
    }


    @Test
    public void test5() {
        try {
            int a = 5 / 0;
        } catch (Exception e) {
            logger.error("Error occur:", e);
        }
    }

    @Test
    public void test6() {
        List list = new ArrayList();
        List<Map<String, Object>> plugins = null;
        list.addAll(plugins);
    }

    @Test
    public void test7() {
        Long a = Long.valueOf(123);
        Long b = Long.valueOf(234);
        if (a > b) {
            logger.info("a>b");
        } else {
            logger.info("a<b");
        }
    }

    @Test
    public void test8() {
        Float aFloat = Float.valueOf(null);
        float x = Float.parseFloat(null);
        logger.info(String.valueOf(aFloat));
        logger.info(String.valueOf(x));
    }

    @Test
    public void test9() {
        Integer integer = Integer.valueOf(null);
        int i = Integer.parseInt(null);
        logger.info(String.valueOf(integer));
        logger.info(String.valueOf(i));
    }

    @Test
    public void test10() {
        Integer a = 1;
        if (a == 1) {
            logger.info(String.valueOf(1));
        }
    }

    @Test
    public void test11() {
        try {
            String message = "Hellow world!";
            int num = 100;
            List<String> list = Arrays.asList("张三", "李四", "王五");
            String str = list.stream().filter(x -> x.equals("王五")).findAny().orElse(null);
            logger.info(str);
        } catch (Exception e) {
            logger.error("error occur:", e);
        }
    }

    @Test
    public void test12() {
        double a = 1.3333;
        float b = (float) a;
        logger.info(String.valueOf(b));
    }

    @Test
    public void test13() {
        if (1 == 1) {
            throw new IllegalStateException("test");
        }
        logger.info("test1");
    }

    @Test
    public void test14() {
        Boolean a = true;
        logger.info("test1");
        List<String> list = new ArrayList<>();
        Map<String, Object> map = (Map<String, Object>) list;
    }

    @Test
    public void test15() {
        String a = "1.00";
        String b = "123,123,123,133";
        double c = Double.parseDouble(a);
        double d = Double.parseDouble(b);
        logger.info(String.valueOf(c));
        logger.info(String.valueOf(d));
    }

    @Test
    public void test16() {
        Map<String, Object> map = new HashMap<>();
        // boolean a = (boolean)map.get("a");
        String str = "test";
        boolean empty = isEmpty("ok");
        logger.info(String.valueOf(empty));
        try {
            int a = 5 / 0;
        } finally {
            logger.info("finally");
        }
    }

    public static boolean isEmpty(final CharSequence cs) {
        return (cs == null || cs.length() == 0);
    }


    @Test
    public void test17() {
       List<Integer> list = new ArrayList<>();
       list.add(1);
       list.add(2);
       list.add(3);
       list.add(4);
       logger.info(String.valueOf(list.size()));
    }

    @Test
    public void test18() {
        String str ="fdsafsda,='fsadfasdfas)d";
        if(str.contains(",") || str.contains("'")) {
            logger.info(str);
            throw new IllegalArgumentException("参数错误！");
        }
    }

    @Test
    public void test19(){
        String a = "A";
        logger.info(String.valueOf(a.hashCode()));
    }

    @Test
    public void test20() {
        Map<String,Object> map = new HashMap<>();
        boolean b = (boolean) map.get("boolean");
    }
    
    @Test
    public void test21() {
        String test= "Hello, world";
        test = COMPILE.matcher(test).replaceAll("");
        boolean test1 = test.equalsIgnoreCase("test");
    }

    @Test
    public void test22() {
        List<String> list = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            logger.info(list.get(i));
        }
    }

    @Test
    public void test23() {
        String a ="1.1234567801234560001";
        BigDecimal b =new BigDecimal(a);
        System.out.printf(a);
    }


}
